package com.powerunion.datacollection.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

import com.powerunion.datacollection.dao.BaseUserDao;
import com.powerunion.datacollection.model.User;
import com.powerunion.util.query.jdbc.QueryParameters;

public class BaseUserDaoImpl extends JdbcBase implements BaseUserDao {

	public BaseUserDaoImpl() {

	}

	public User getUser(String code) throws Exception {
		QueryParameters params = new QueryParameters();
		params.addParameter(code, Types.VARCHAR);
		return (User) this.findByKey(this.sqlGetByKey(), params, "getData");
	}

	protected String sqlGetByKey() {
		return "select user_code,full_name from base_user where user_code = ?";
	}

	public final User getData(ResultSet rsData) throws SQLException {
		User user = new User();
		user.setUserCode(rsData.getString("user_code"));
		user.setUserName(rsData.getString("full_name"));

		return user;
	}

}
